import { ref } from 'vue'

export function usePageModal(
  confirm?: any,
  editCb?: any
): [any, any, (e: any) => void, (e: any) => void] {
  const pageModalRef = ref()
  const defaultInfo = ref({}) //回显数据
  // 这是page-content 打开新建数据时候model调用的函数
  const handleNewData = () => {
    pageModalRef.value.dialogVisible = true
    defaultInfo.value = {}
    confirm && confirm()
  }
  // 这是page-content 编辑数据时候调的函数
  const handleEdit = (obj: any) => {
    pageModalRef.value.dialogVisible = true
    defaultInfo.value = obj
    editCb && editCb(obj)
  }
  return [pageModalRef, defaultInfo, handleNewData, handleEdit]
}
